package ducna.android.aoeclip.screen.category.adapter;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import java.util.ArrayList;

import ducna.android.aoeclip.common.model.entity.Category;
import ducna.android.aoeclip.common.utils.Constant;
import ducna.android.aoeclip.common.utils.Logger;
import ducna.android.aoeclip.screen.category.fragment.ListArticleFragment;

/**
 * Created by DUCNA on 11/7/2014.
 * adapter viewPager
 */
public class ArticleFragmentPagerAdapter extends FragmentPagerAdapter implements Constant{

    private static final String TAG = "ArticleFragmentPagerAdapter";
    private ArrayList<Category> dataCategories;
    public ArticleFragmentPagerAdapter(FragmentManager fragmentManager, Bundle bundle){
        super(fragmentManager);
        dataCategories = bundle.getParcelableArrayList(ARGUMENT_CATEGORIES);
        Logger.out(TAG, "dataCategories: " + dataCategories.size());
    }
    @Override
    public Fragment getItem(int position) {
        Bundle args = new Bundle();
        Fragment fragment = new ListArticleFragment();
        args.putString(ARGUMENT_CATEGORY_ID, dataCategories.get(position).getId());
        args.putInt(ARGUMENT_FRAGMENT_ID, position);
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    public int getCount() {
        return dataCategories.size();
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return dataCategories.get(position).getCateName();
    }
}
